package com.zy.design.pattern.factory.simple;

import com.zy.design.pattern.factory.base.IRuleConfigParser;

import java.util.Optional;

/**
 * @author zhaoyi
 * @date 2021/3/29 18:06
 * 简单工厂模式
 */
public class SimpleConfigSource {

    public void load(String filePath) {
        String file = getFileExtension(filePath);
        IRuleConfigParser parser = ConfigParserFactory.createParser(file);
        String name = "基础版 - 简单工厂模式";
        parser.parse(name);
    }

    private String getFileExtension(String filePath) {
        return Optional.ofNullable(filePath)
                .map(r -> {
                    String[] split = r.split("\\.");
                    return split[split.length - 1];
                }).orElseThrow(()->new IllegalArgumentException(filePath));
    }

}
